package golf.stockinfo.buysellsimulation;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.TreeMap;

public class SimulationOutputData implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1794803202157908201L;
	
	public static TreeMap<String, ArrayList<SimulationData>> SIMULATION_OUTPUT = new TreeMap<String, ArrayList<SimulationData>>();
	public static ArrayList<Date> DATE_ARRAY = new ArrayList<Date>();
	
	public static void unload(String filename){
		try {
			//unload the Simulation Output first
			FileOutputStream fout = new FileOutputStream(filename + "_SimObj.dat");
			ObjectOutputStream oos = new ObjectOutputStream(fout);
			oos.writeObject(SIMULATION_OUTPUT);
			oos.close();
			fout.close();
			
			//unload the Simulation Date array
			fout = new FileOutputStream(filename + "_DateArrObj.dat");
			oos = new ObjectOutputStream(fout);
			oos.writeObject(DATE_ARRAY);
			oos.close();
			fout.close();
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@SuppressWarnings("unchecked")
	public static void load(String filename){
		try {
			//load the Simulation Output first
			FileInputStream fin = new FileInputStream(filename + "_SimObj.dat");
			ObjectInputStream ois = new ObjectInputStream(fin);
			SIMULATION_OUTPUT = (TreeMap<String, ArrayList<SimulationData>>) ois.readObject();
			ois.close();
			fin.close();
			
			//load the Simulation Date first
			fin = new FileInputStream(filename + "_DateArrObj.dat");
			ois = new ObjectInputStream(fin);
			DATE_ARRAY = (ArrayList<Date>) ois.readObject();
			ois.close();
			fin.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

}
